package com.itrh.auth.controller;

import com.itrh.auth.service.IPermissionService;
import com.itrh.auth.domain.Permission;
import com.itrh.auth.query.PermissionQuery;
import com.itrh.base.annotation.AuthPermission;
import com.itrh.org.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/permission")
@AuthPermission(name = "权限管理")
public class PermissionController {
    @Resource
    public IPermissionService permissionService;


    @PutMapping
    @AuthPermission(name = "添加/修改权限")
    public Result addOrUpdate(@RequestBody Permission permission){
        return permissionService.saveOrUpdate(permission);
    }

    @DeleteMapping(value="/{id}")
    @AuthPermission(name = "删除权限")
    public Result delete(@PathVariable Long id) {
        return permissionService.deleteById(id);
    }
	
    //获取用户
    @GetMapping("/{id}")
    @AuthPermission(name = "获取权限")
    public Result get(@PathVariable Long id) {
        return permissionService.selectById(id);
    }

    @GetMapping
    @AuthPermission(name = "获取权限列表")
    public Result list() {
        return permissionService.selectAll();
    }

    @PostMapping
    @AuthPermission(name = "条件分页获取权限列表")
    public Result pageList(@RequestBody PermissionQuery query) {
        System.out.println("query:" + query);
        return permissionService.pageList(query);
    }

    @PatchMapping
    @AuthPermission(name = "批量删除权限")
    public Result batchRemove(@RequestBody List<Long> ids){
        return permissionService.batchRemove(ids);
    }

    @GetMapping("/tree")
    @AuthPermission(name = "获取权限树")
    public Result getPermissionTree() {
        return permissionService.getPermissionTree();
    }
}
